dp = [0 for i in xrange(10000)]
def f(n):
    i = 1
    s = 0
    while i < n:
        if n % i == 0:
            j = n / i
            if i > j:
                break
            if i == j:
                s += i
                break
            s += i
            if j < n:
                s += j
        i += 1
    return s

ans = 0
for i in xrange(1, 10000):
    dp[i] = f(i)
for i in xrange(1, 10000):
    if dp[i] < 10000 and i != dp[i] and i == dp[dp[i]]:
        print i, dp[i]
        ans += i
print ans
